forked from thrasher-corp/gocryptotrader
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/sub pairs #3
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
IsInit was basically the same as IsConnected. Any time Connect was called both would be set to true. Any time we had a disconnect they'd both be set to false Shutdown() incorrectly didn't setInit(false) SetProxyAddress simplified to only reconnect a connected Websocket. Any other state means it hasn't been Connected, or it's about to reconnect anyway. There's no handling for IsConnecting previously, either, so I've wrapped that behind the main mutex.
This allows for testing and avoids the repetition. If each returned error is a error.New() you can never use errors.Is()
Testing just the last id doesn't feel very robust
This was spurred by looking at the setState call in trafficMonitor and the effect on blocking and efficiency. With the new atomic types in Go 1.19, and the small types in use here, atomics should be safe for our usage. bools should be truly atomic, and uint32 is atomic when the accepted value range is less than one byte/uint8 since that can be written atomicly by concurrent processors. Maybe that's not even a factor any more, however we don't even have to worry enough to check.
trafficMonitor had a check throttle at the end of the for loop to stop it just gobbling the (blocking) trafficAlert channel non-stop. That makes sense, except that nothing is sent to the trafficAlert channel if there's no listener. So that means that it's out by one second on the trafficAlert, because any traffic received during the pause is doesn't try to send a traffic alert. The unstopped timer is deliberately leaked for later GC when shutdown. It won't delay/block anything, and it's a trivial memory leak during an infrequent event. Deliberately Choosing to recreate the timer each time instead of using Stop, drain and reset
Fix race on changing trafficCheckInterval
gbjk
force-pushed
the
feature/sub_pairs
branch
5 times, most recently
from
February 19, 2024 07:22
33e3860
to
00a56cc
Compare
gbjk
force-pushed
the
feature/websocket_state
branch
from
February 20, 2024 09:13
c6dc10c
to
7443745
Compare
trafficMonitor does not need to set the connection to be connected. Connect() does that. Anything after that should result in a full shutdown and restart. It can't and shouldn't become connected unexpectedly, and this is most likely a race anyway. Also dropped trafficCheckInterval to 100ms to mitigate races of traffic alerts being buffered for too long.
gbjk
force-pushed
the
feature/websocket_state
branch
from
February 20, 2024 09:16
7443745
to
2f6bfc0
Compare
Retain the .msg field of a go fmt.Errorf .msg field returned by .Error() when wrapping multiple errors. This fixes a situation where a nested stack of errors would lose formatting information, which is often used to supply identifying context. e.g. ``` err = fmt.Errorf("%w `%s`: %w", errParsingField, fieldName, parsingError) errs = common.AppendError(errs, err) ``` This isn't really an issue with our implementation; Calling Unwrap() on a fmt.Errorf() which returns a wrapErrors will lose that formatting. Our issue was that we were using just Unwrap() to bind together our chain-of-custody.
If the exchange passed in already has a websocket, don't clobber it
instead of errChannelAlreadySubscribed
gbjk
force-pushed
the
feature/sub_pairs
branch
5 times, most recently
from
February 21, 2024 07:48
f62e3ce
to
dcfd5a5
Compare
Given that some subscriptions have multiple pairs, support that as the standard.
Except Kraken, which needs atomicity to not collide with upcoming work
Note: This is a naieve implementation because we want to rebase the kraken websocket rewrite on top of this
gbjk
force-pushed
the
feature/sub_pairs
branch
from
February 22, 2024 03:36
c7fa2b4
to
0fbb7cd
Compare
We deliberately use Equal over Len to avoid spamming the contents of large Slices
gbjk
force-pushed
the
feature/sub_pairs
branch
8 times, most recently
from
February 23, 2024 03:06
1b6804b
to
7e58e5f
Compare
gbjk
force-pushed
the
feature/sub_pairs
branch
from
February 23, 2024 03:21
7e58e5f
to
579ec55
Compare
gbjk
force-pushed
the
feature/websocket_state
branch
2 times, most recently
from
February 23, 2024 06:01
0b03808
to
9aca06e
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.